<template>
    <div>
        <el-card class="box-card">
            <div slot="header" class="clearfix">
                <span>我是ChildCom组件</span>
                <el-button style="float: right; padding: 3px 0" type="text"
                    @click="parentCallBack('我来自child组件,调用index 中 parentCallBack方法')">
                    调用父级parentCallBack方法
                </el-button>

                <el-button style="float: right; padding: 3px 0" type="text" @click="$emit('update:textValue', '修改后的值')">
                    修改父级 textValue 值
                </el-button>

            </div>
            <div class="text item">
                {{ childData }}
            </div>
        </el-card>
        <el-card class="box-card">
            <div slot="header" class="clearfix">
                我是子子组件 childChildCom
            </div>
            <div class="text item">
                <childChildCom></childChildCom>
            </div>
        </el-card>


    </div>
</template>

<script>
import childChildCom from './childChildCom.vue'
export default {
    name: 'childComponent',
    components: { childChildCom },
    props: ["childData"],
    data() {
        return {}
    },
    methods: {
        parentCallBack(msg) {
            this.$emit("parentCallBack", msg);
            console.log('childCom-callBack', msg);
        },
        childMethod(msg) {
            console.log('childCom-childMethon', msg)
            this.$message({ message: msg, type: 'success' })
        }
    },
    watch: {
        //监听 childData
        childData(newData, oldData) {
            const msg = `oldData:${oldData};\n newData:${newData}`;
            this.$message({ message: msg, type: 'success' })
            console.log(msg)
        }
    }
}
</script>

<style>
.text {
    font-size: 14px;
}

.item {
    margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
    display: table;
    content: "";
}

.clearfix:after {
    clear: both
}
</style>